package Pokero;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.lang.reflect.Array;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextPane;

public class AuctionFrame extends JFrame implements ActionListener {
        private JFrame frame;
    static JTextPane text1;
    static JTextPane text2;
    static JTextPane text3;
    static JTextPane text4;
 
    private JCheckBox box1;
    private static JButton raise1;
    private static JButton call1;
    private static JButton all1;
    private static JButton check1;
    private static JButton next;
    private JButton fold1;

    private JCheckBox box2;
    private static JButton raise2;
    private static JButton call2;
    private static JButton all2;
    private static JButton check2;
    private JButton fold2;

    private JCheckBox box3;
    private static JButton raise3;
    private static JButton call3;
    private static JButton all3;
    private static JButton check3;
    private JButton fold3;

    private JCheckBox box4;
    private static JButton raise4;
    private static JButton call4;
    private static JButton all4;
    private static JButton check4;
    
    private JButton fold4;
    private JButton end;
    static int[] account = {-1,-1,-1,-1};
    private int Gen;
    private int PNumber;
    public static Boolean[] active = {false,false,false,false};
    
    public AuctionFrame(int HumAmount) {
            
        //okno
        super("Licytacja");
        frame = new JFrame();
        setVisible(true);
        setSize(720,200);
        setLayout(new FlowLayout());
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        
        
        
        
        //text gracz 1
        Font f = new Font(Font.SANS_SERIF, 5, 17);
        text1 = new JTextPane();
        text1.setVisible(true);
        text1.setText("Gracz numer 1 Kwota:" + Integer.toString(account[0]));               
        text1.setEditable(false);
        text1.setBackground(null);
        text1.setFont(f);
        
        add(text1);
        //buttony gracz 1

        raise1 = new JButton("Podnies o 5");
        call1 = new JButton("Rownaj");
        fold1 = new JButton("Pas");
        all1 = new JButton("All-in");
        check1 = new JButton("Sprawdz");
        box1 = new JCheckBox("Gotowy?");
        
        box1.setEnabled(false);
        

        raise1.addActionListener(this);
        call1.addActionListener(this);
        fold1.addActionListener(this);
        all1.addActionListener(this);
        check1.addActionListener(this);
        

        add(raise1);
        add(call1);
        add(fold1);
        add(all1);
        add(check1);
        
        // 2 graczy aukcja
        // text drugi gracz
        text2 = new JTextPane();
        text2.setVisible(true);
        text2.setText("Gracz numer 2 Kwota:" + Integer.toString(account[1]));               
        text2.setEditable(false);
        text2.setBackground(null);
        text2.setFont(f);
        
        add(text2);
        //buttony gracz 2
        

        raise2 = new JButton("Podnies o 5");
        call2 = new JButton("Rownaj");
        fold2 = new JButton("Pas");
        all2 = new JButton("All-in");
        check2 = new JButton("Sprawdz");
        box2 = new JCheckBox("Gotowy?");

        box2.setEnabled(false);
        
        raise2.addActionListener(this);
        call2.addActionListener(this);
        fold2.addActionListener(this);
        all2.addActionListener(this);
        check2.addActionListener(this);
        
        

        add(raise2);
        add(call2);
        add(fold2);
        add(all2);
        add(check2);
        
        if(HumAmount < 2) {
        		all2.setVisible(false);
    			check2.setVisible(false);
                raise2.setVisible(false);
                call2.setVisible(false);
                fold2.setVisible(false);
                text2.setVisible(false);
        }
        
        // 3 graczy aukcja
        // text trzeci gracz
        text3 = new JTextPane();
        text3.setVisible(true);
        text3.setText("Gracz numer 3 Kwota:" + Integer.toString(account[2]));               
        text3.setEditable(false);
        text3.setBackground(null);
        text3.setFont(f);
        
        add(text3);
        //buttony gracz 3
        

        raise3 = new JButton("Podnies o 5");
        call3 = new JButton("Rownaj");
        fold3 = new JButton("Pas");
        all3 = new JButton("All-in");
        check3 = new JButton("Sprawdz");
        box3 = new JCheckBox("Gotowy?");
        
        box3.setEnabled(false);

        raise3.addActionListener(this);
        call3.addActionListener(this);
        fold3.addActionListener(this);
        all3.addActionListener(this);
        check3.addActionListener(this);
        

        add(raise3);
        add(call3);
        add(fold3);
        add(all3);
        add(check3);
        
        if(HumAmount < 3) {
        		all3.setVisible(false);
    			check3.setVisible(false);
                raise3.setVisible(false);
                call3.setVisible(false);
                fold3.setVisible(false);
                text3.setVisible(false);
        }
        
        
        
        // 4 graczy aukcja
        // text czwarty gracz
        text4 = new JTextPane();
        text4.setVisible(true);
        text4.setText("Gracz numer 4 Kwota:" + Integer.toString(account[3]));               
        text4.setEditable(false);
        text4.setBackground(null);
        text4.setFont(f);
        
        add(text4);
        //buttony gracz 4
        
        box4 = new JCheckBox("Gotowy?");
        raise4 = new JButton("Podnies o 5");
        call4 = new JButton("Rownaj");
        fold4 = new JButton("Pas");
        all4 = new JButton("All-in");
        check4 = new JButton("Sprawdz");
        
        box4.setEnabled(false);

        raise4.addActionListener(this);
        call4.addActionListener(this);
        fold4.addActionListener(this);
        all4.addActionListener(this);
        check4.addActionListener(this);
        

        add(raise4);
        add(call4);
        add(fold4);
        add(all4);
        add(check4);
        
        if(HumAmount < 4) {
        		all4.setVisible(false);
        		check4.setVisible(false);
                raise4.setVisible(false);
                call4.setVisible(false);
                fold4.setVisible(false);
                text4.setVisible(false);
        }
        
        next = new JButton("Start");
        end = new JButton("Koniec licytacji");
                
        next.addActionListener(this);
        end.addActionListener(this);
        
        add(next);
        add(end);
        
        raise1.setEnabled(false);
	    call1.setEnabled(false);
	    all1.setEnabled(false);
	    fold1.setEnabled(false);
	    check1.setEnabled(false);
        
        raise2.setEnabled(false);
	    call2.setEnabled(false);
	    all2.setEnabled(false);
	    fold2.setEnabled(false);
	    check2.setEnabled(false);
	    
	    raise3.setEnabled(false);
	    call3.setEnabled(false);
	    all3.setEnabled(false);
	    fold3.setEnabled(false);
	    check3.setEnabled(false);
                
	    raise4.setEnabled(false);
	    call4.setEnabled(false);
	    all4.setEnabled(false);
	    fold4.setEnabled(false);
	    check4.setEnabled(false);
	    
	    Random Generator = new  Random();
	    int Gen = Generator.nextInt(4);
	    
	    PNumber = Gen;
	    
	  //blokada rozmiaru okna
        this.addComponentListener(new ComponentAdapter(){
    public void componentResized(ComponentEvent e){
        Dimension d=AuctionFrame.this.getSize();
        if(d.width != 720)
            d.width=720;
        if(d.height != 200)
            d.height=200;
        AuctionFrame.this.setSize(d);
    }
});
	    
	    
	    
	    if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == -1) {
	    	new Komunikat();
	    	dispose();
	    	
	    }
	    
	    
	    
    }   

    @Override
    public void actionPerformed(ActionEvent e) {
            Object source = e.getSource();
            Random Generator = new  Random();
            
            // pierwszy gracz
            
            if(source == fold1) {
                raise1.setEnabled(false);
                call1.setEnabled(false);
                fold1.setEnabled(false);
                check1.setEnabled(false);
                all1.setEnabled(false);
                account[0] = -1;
                text1.setText("Gracz numer 1 Kwota: Pas");
                if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == -1) {
                	account[0] = 0;
                	account[1] = 0;
                	account[2] = 0;
                	account[3] = 0;
                	PokerFrame.pula = 0;
                	dispose();
                }
            }
            if(source == raise1) {
            	int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];
                                        
                if(PokerFrame.HumanPlayers[0].money + account[0] >= max + 5 && account[0] <= max) {
                        PokerFrame.pula += (max - account[0] + 5);
                        account[0] += (max - account[0] + 5);
                        PokerFrame.HumanPlayers[0].money -= (max - account[0] + 5);

                        text1.setText("Gracz numer 1 Kwota:" + Integer.toString(account[0]));
                        PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                        
                        if(PlayerFrame.CPUAmount == 1) {
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 0);
                        }                        
                        if(PlayerFrame.CPUAmount == 2) {
                                
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 0);
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 1);
                        }
                        if(PlayerFrame.CPUAmount == 3) {
                                
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 0);
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 1);
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 2);
                        }
                }
                else {
                        //call1.setEnabled(false);
                        raise1.setEnabled(false);
                }
            }
            if(source == call1) {
                int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];
                                        
                if(PokerFrame.HumanPlayers[0].money + account[0] >= max && account[0] < max) {
                	PokerFrame.pula += (max - account[0]);
                	account[0] += (max - account[0]);
                	PokerFrame.HumanPlayers[0].money -= (max - account[0]);
                	PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                	text1.setText("Gracz numer 1 Kwota:" + Integer.toString(account[0]));
                	
                }
                else if(PokerFrame.HumanPlayers[0].money < max - account[0])
                        call1.setEnabled(false);
                else
                        call1.setEnabled(true);
            }
            
            if(source == all1) {
            	/*
            	 * TODO
            	 * metoda porównująca układy kart
            	 * 
            	 * 
            	 * @return zwyciezce + rozdanie kasy (wygrywający bierze od każdego tyle co zastawił
            	 * w przypadku gdyby ktoś dał mniej to bierze wszystko to co ktoś zastawił)
            	 * 
            	 */
            }
            if(source == check1) {
            	if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == 0) {
            		if(account[1] != -1) {
        				raise2.setEnabled(true);
        				call2.setEnabled(true);
        				all2.setEnabled(true);
        				fold2.setEnabled(true);
        				check2.setEnabled(true);
        			}
        		
            		raise1.setEnabled(false);
        	    	call1.setEnabled(false);
        	    	all1.setEnabled(false);
        	    	fold1.setEnabled(false);
        	    	check1.setEnabled(false);
        	    
        	    	raise3.setEnabled(false);
        	    	call3.setEnabled(false);
        	    	all3.setEnabled(false);
        	    	fold3.setEnabled(false);
        	    	check3.setEnabled(false);
                        
        	    	raise4.setEnabled(false);
        	    	call4.setEnabled(false);
        	    	all4.setEnabled(false);
        	    	fold4.setEnabled(false);
        	    	check4.setEnabled(false);
        	    
        	    	PNumber = 1;
            	}
            }
            
            
            
            // drugi gracz

            if(source == fold2) {
                raise2.setEnabled(false);
                call2.setEnabled(false);
                fold2.setEnabled(false);
                check2.setEnabled(false);
                all2.setEnabled(false);
                account[1] = -1;
                text2.setText("Gracz numer 2 Kwota: Pas");
                if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == -1) {
                	account[0] = 0;
                	account[1] = 0;
                	account[2] = 0;
                	account[3] = 0;
                	PokerFrame.pula = 0;
                	dispose();
                }
            }
            if(source == raise2) {
            	int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];

                if(PokerFrame.HumanPlayers[1].money + account[1] >= max + 5 && account[1] <= max) {
                        PokerFrame.pula += (max - account[1] + 5);
                        account[1] += (max - account[1] + 5);
                        PokerFrame.HumanPlayers[1].money -= (max - account[1] + 5);
                        
                        text2.setText("Gracz numer 2 Kwota:" + Integer.toString(account[1]));
                        PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                        
                        if(PlayerFrame.CPUAmount == 1) {
                                Gen = Generator.nextInt(2);
                                Bot.Auction(Gen, 0);
                        }                        
                        if(PlayerFrame.CPUAmount == 2) {
                                
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 0);
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 1);
                        }
                }
                else {
                        call2.setEnabled(false);
                        raise2.setEnabled(false);
                }
            }
            if(source == call2) {
                int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];

                if(PokerFrame.HumanPlayers[1].money >= max && account[1] < max) {
                        PokerFrame.pula += (max - account[1]);
                        account[1] += (max - account[1]);
                        PokerFrame.HumanPlayers[1].money -= (max - account[1]);
                        text2.setText("Gracz numer 2 Kwota:" + Integer.toString(account[1]));
                        PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                }
                else if(PokerFrame.HumanPlayers[1].money < max - account[1])
                        call2.setEnabled(false);
                else
                        call2.setEnabled(true);
            }
            
            if(source == all2) {
            	/*
            	 * TODO
            	 * metoda porównująca układy kart
            	 * 
            	 * 
            	 * @return zwyciezce + rozdanie kasy (wygrywający bierze od każdego tyle co zastawił
            	 * w przypadku gdyby ktoś dał mniej to bierze wszystko to co ktoś zastawił)
            	 * 
            	 */
            }
            if(source == check2) {
            	if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == 0) {
            		if(account[2] != -1) {
            			raise3.setEnabled(true);
            			call3.setEnabled(true);
            			all3.setEnabled(true);
            			fold3.setEnabled(true);
            			check3.setEnabled(true);
            		}
    	    
            		raise2.setEnabled(false);
            		call2.setEnabled(false);
            		all2.setEnabled(false);
            		fold2.setEnabled(false);
            		check2.setEnabled(false);
    	    
            		raise1.setEnabled(false);
            		call1.setEnabled(false);
            		all1.setEnabled(false);
            		fold1.setEnabled(false);
            		check1.setEnabled(false);
                    
            		raise4.setEnabled(false);
            		call4.setEnabled(false);
            		all4.setEnabled(false);
            		fold4.setEnabled(false);
            		check4.setEnabled(false);
    	    
            		PNumber = 2;
            	}
            }
           
            
            
            // trzeci gracz

            if(source == fold3) {
                raise3.setEnabled(false);
                call3.setEnabled(false);
                fold3.setEnabled(false);
                check3.setEnabled(false);
                all3.setEnabled(false);
                account[2] = -1;
                text3.setText("Gracz numer 3 Kwota: Pas");
                if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == -1) {
                	account[0] = 0;
                	account[1] = 0;
                	account[2] = 0;
                	account[3] = 0;
                	PokerFrame.pula = 0;
                	dispose();
                }
            }
            if(source == raise3) {
            	int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];

                if(PokerFrame.HumanPlayers[2].money + account[2] >= max + 5 && account[2] <= max) {
                        PokerFrame.pula += (max - account[2] + 5);
                        PokerFrame.HumanPlayers[2].money -= (max - account[2] + 5);
                        account[2] += (max - account[2] + 5);

                        text3.setText("Gracz numer 3 Kwota:" + Integer.toString(account[2]));
                        PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                }
                else {
                        call3.setEnabled(false);
                        raise3.setEnabled(false);
                }
            }
            if(source == call3) {
                int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];

                if(PokerFrame.HumanPlayers[2].money >= max && account[2] < max) {
                	PokerFrame.pula += (max - account[2]);
                    PokerFrame.HumanPlayers[2].money -= (max - account[2]);
                    account[2] += (max - account[2]);
                    text3.setText("Gracz numer 3 Kwota:" + Integer.toString(account[2]));
                    PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                        
                        if(PlayerFrame.CPUAmount == 1) {
                                Gen = Generator.nextInt(4);
                                Bot.Auction(Gen, 0);
                        }
                }
                if(PokerFrame.HumanPlayers[2].money < max - account[2])
                        call3.setEnabled(false);
                else
                        call3.setEnabled(true);
            }
            
            if(source == all3) {
            	/*
            	 * TODO
            	 * metoda porównująca układy kart
            	 * 
            	 * 
            	 * @return zwyciezce + rozdanie kasy (wygrywający bierze od każdego tyle co zastawił
            	 * w przypadku gdyby ktoś dał mniej to bierze wszystko to co ktoś zastawił)
            	 * 
            	 */
            }
            if(source == check3) {
            	if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == 0) {
            		if(account[3] != -1) {
            			raise4.setEnabled(true);
            			call4.setEnabled(true);
            			all4.setEnabled(true);
            			fold4.setEnabled(true);
            			check4.setEnabled(true);
            		}
    	    
            		raise2.setEnabled(false);
            		call2.setEnabled(false);
            		all2.setEnabled(false);
            		fold2.setEnabled(false);
            		check2.setEnabled(false);
    	    
            		raise1.setEnabled(false);
            		call1.setEnabled(false);
            		all1.setEnabled(false);
            		fold1.setEnabled(false);
            		check1.setEnabled(false);
                    
            		raise4.setEnabled(false);
            		call4.setEnabled(false);
            		all4.setEnabled(false);
            		fold4.setEnabled(false);
            		check4.setEnabled(false);
    	    
            		PNumber = 3;
            	}
            }
            
            
            //czwarty gracz

            if(source == fold4) {
                raise4.setEnabled(false);
                call4.setEnabled(false);
                fold4.setEnabled(false);
                check4.setEnabled(false);
                all4.setEnabled(false);
                account[3] = -1;
                text4.setText("Gracz numer 4 Kwota: Pas");
                if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == -1) {
                	account[0] = 0;
                	account[1] = 0;
                	account[2] = 0;
                	account[3] = 0;
                	PokerFrame.pula = 0;
                	dispose();
                }
            }
            if(source == raise4) {
            	int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];

                if(PokerFrame.HumanPlayers[3].money + account[3] >= max + 5 && account[3] <= max) {
                	PokerFrame.pula += (max - account[3] + 5);
                    PokerFrame.HumanPlayers[3].money -= (max - account[3] + 5);
                    account[3] += (max - account[3] + 5);

                        text4.setText("Gracz numer 4 Kwota:" + Integer.toString(account[3]));
                        PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                }
                else {
                        call4.setEnabled(false);
                        raise4.setEnabled(false);
                }
                        
            }
            if(source == call4) {
                int max = 0;
                if(max < account[0])
                        max = account[0];
                if(max < account[1])
                        max = account[1];
                if(max < account[2])
                        max = account[2];
                if(max < account[3])
                        max = account[3];

                if(PokerFrame.HumanPlayers[3].money >= max && account[3] < max) {
                	PokerFrame.pula += (max - account[3]);
                    PokerFrame.HumanPlayers[3].money -= (max - account[3]);
                    account[3] += (max - account[3]);
                    text4.setText("Gracz numer 4 Kwota:" + Integer.toString(account[3]));
                    PokerFrame.bpula.setText("Pula wynosi: " + Integer.toString(PokerFrame.pula));
                }
                else if(PokerFrame.HumanPlayers[3].money < max - account[3])
                        call4.setEnabled(false);
                else
                        call4.setEnabled(true);
            }     
            if(source == all4) {
            	/*
            	 * TODO
            	 * metoda porównująca układy kart
            	 * 
            	 * 
            	 * @return zwyciezce + rozdanie kasy (wygrywający bierze od każdego tyle co zastawił
            	 * w przypadku gdyby ktoś dał mniej to bierze wszystko to co ktoś zastawił)
            	 * 
            	 */
            }
            if(source == check4) {
            	if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == 0) {
            		if(account[0] != -1) {
            			raise1.setEnabled(true);
            			call1.setEnabled(true);
            			all1.setEnabled(true);
            			fold1.setEnabled(true);
            			check1.setEnabled(true);
            		}
    	    
            		raise2.setEnabled(false);
            		call2.setEnabled(false);
            		all2.setEnabled(false);
            		fold2.setEnabled(false);
            		check2.setEnabled(false);
    	    
            		raise1.setEnabled(false);
            		call1.setEnabled(false);
            		all1.setEnabled(false);
            		fold1.setEnabled(false);
            		check1.setEnabled(false);
                    
            		raise4.setEnabled(false);
            		call4.setEnabled(false);
            		all4.setEnabled(false);
            		fold4.setEnabled(false);
            		check4.setEnabled(false);
    	    
            		PNumber = 0;
            	}
            }
            
            if(source == next) {
            	if(next.getText() == "Start")
            		next.setText("Kolejny gracz");
            	if(account[0] == account[1] && account[0] == account[2] && account[0] == account[3] && account[0] == -1) {
            		dispose();
            	}

            	if(PNumber == 0) {
            		if(account[0] != -1) {
            			raise1.setEnabled(true);
            			call1.setEnabled(true);
            			all1.setEnabled(true);
            			fold1.setEnabled(true);
            			check1.setEnabled(true);
            		}
            	    
            	    raise2.setEnabled(false);
            	    call2.setEnabled(false);
            	    all2.setEnabled(false);
            	    fold2.setEnabled(false);
            	    check2.setEnabled(false);
            	    
            	    raise3.setEnabled(false);
            	    call3.setEnabled(false);
            	    all3.setEnabled(false);
            	    fold3.setEnabled(false);
            	    check3.setEnabled(false);
                            
            	    raise4.setEnabled(false);
            	    call4.setEnabled(false);
            	    all4.setEnabled(false);
            	    fold4.setEnabled(false);
            	    check4.setEnabled(false);
            	    
            	    PNumber = 1;
            	} else 
            		if(PNumber == 1) {
            			if(account[1] != -1) {
            				raise2.setEnabled(true);
            				call2.setEnabled(true);
            				all2.setEnabled(true);
            				fold2.setEnabled(true);
            				check2.setEnabled(true);
            			}
            		
            		raise1.setEnabled(false);
            	    call1.setEnabled(false);
            	    all1.setEnabled(false);
            	    fold1.setEnabled(false);
            	    check1.setEnabled(false);
            	    
            	    raise3.setEnabled(false);
            	    call3.setEnabled(false);
            	    all3.setEnabled(false);
            	    fold3.setEnabled(false);
            	    check3.setEnabled(false);
                            
            	    raise4.setEnabled(false);
            	    call4.setEnabled(false);
            	    all4.setEnabled(false);
            	    fold4.setEnabled(false);
            	    check4.setEnabled(false);
            	    
            	    PNumber = 2;
            	} else
            		if(PNumber == 2) {
            			if(account[2] != -1) {
            				raise3.setEnabled(true);
            				call3.setEnabled(true);
            				all3.setEnabled(true);
            				fold3.setEnabled(true);
            				check3.setEnabled(true);
            			}
            	    
            		raise2.setEnabled(false);
            	    call2.setEnabled(false);
            	    all2.setEnabled(false);
            	    fold2.setEnabled(false);
            	    check2.setEnabled(false);
            	    
            	    raise1.setEnabled(false);
            	    call1.setEnabled(false);
            	    all1.setEnabled(false);
            	    fold1.setEnabled(false);
            	    check1.setEnabled(false);
                            
            	    raise4.setEnabled(false);
            	    call4.setEnabled(false);
            	    all4.setEnabled(false);
            	    fold4.setEnabled(false);
            	    check4.setEnabled(false);
            	    
            	    PNumber = 3;
            	} else           	
            		if(PNumber == 3) {
            			if(account[3] != -1) {
            				raise4.setEnabled(true);
            				call4.setEnabled(true);
            				all4.setEnabled(true);
            				fold4.setEnabled(true);
            				check4.setEnabled(true);
            			}
            	    
            		raise2.setEnabled(false);
            	    call2.setEnabled(false);
            	    all2.setEnabled(false);
            	    fold2.setEnabled(false);
            	    check2.setEnabled(false);
            	    
            	    raise3.setEnabled(false);
            	    call3.setEnabled(false);
            	    all3.setEnabled(false);
            	    fold3.setEnabled(false);
            	    check3.setEnabled(false);
                            
            	    raise1.setEnabled(false);
            	    call1.setEnabled(false);
            	    all1.setEnabled(false);
            	    fold1.setEnabled(false);
            	    check1.setEnabled(false);
            	    
            	    PNumber = 0;
            	}
            }
            
            
            
            // porównania i następna runda
            if(source == end) {
                 if(PlayerFrame.HumAmount == 1) {
                    
                                     
                	 int champion = 0;
                	 int uklad1 = 0;
                     int uklad2 = 0;
                     int uklad3 = 0;
                     int uklad4 = 0;
                     
                     uklad1 = Scheme.Uklady(PokerFrame.HumanPlayers[0].Hand);
                     uklad2 = Scheme.Uklady(PokerFrame.CPUPlayers[0].Hand);
                     uklad3 = Scheme.Uklady(PokerFrame.CPUPlayers[1].Hand);
                     uklad4 = Scheme.Uklady(PokerFrame.CPUPlayers[2].Hand);
                     
                         if(account[0] < 0)
                         {
                                 uklad1 = -1;
                         }
                         if(account[1] < 0)
                         {
                                 uklad2 = -1;
                         }
                         if(account[2] < 0)
                         {
                                 uklad3 = -1;
                         }
                         if(account[3] < 0)
                         {
                                 uklad4 = -1;
                         }
                     
                            // champion = Scheme.compareCards(uklad1, uklad2, uklad3, uklad4);
                             int max = uklad1;
                             if(max < uklad2)
                             {
                                     max = uklad2;
                                     champion = 1;
                             }
                             if(max < uklad3)
                             {
                                     max = uklad3;
                                     champion = 2;
                             }
                             if(max < uklad4)
                             {
                                     max = uklad4;
                                     champion = 3;
                             }
                            
                             if(max == uklad1 && max == uklad2 && max == uklad3 && max == uklad4)
                             {
                                     new WinnerFrame("Remis pomiedzy wszystkimi graczami!");
                                     PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/4);
                                     PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/4);
                                     PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/4);
                                     PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + (PokerFrame.pula/4);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad1 && max == uklad2 && max == uklad3)
                             {
                                     new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[0].imie + " " + PokerFrame.CPUPlayers[1].imie);
                                     PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/3);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad1 && max == uklad2 && max == uklad4)
                             {
                                     new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[0].imie + " " + PokerFrame.CPUPlayers[2].imie);
                                     PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + (PokerFrame.pula/3);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad1 && max == uklad3 && max == uklad4)
                             {
                                     new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[1].imie + " " + PokerFrame.CPUPlayers[2].imie);
                                     PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + (PokerFrame.pula/3);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad2 && max == uklad3 && max == uklad4)
                             {
                                     new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.CPUPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.CPUPlayers[2].imie);
                                     PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/3);
                                     PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + (PokerFrame.pula/3);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad1 && max == uklad2)
                             {
                                     new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[0].imie);
                                     PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                                     PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad1 && max == uklad3)
                             {
                                     new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[1].imie);
                                     PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                                     PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/2);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad1 && max == uklad4)
                             {
                                     new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[2].imie);
                                     PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                                     PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + (PokerFrame.pula/2);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad2 && max == uklad3)
                             {
                                     new WinnerFrame("Remis pomiedzy " +  PokerFrame.CPUPlayers[0].imie + " " + PokerFrame.CPUPlayers[1].imie);
                                     PokerFrame.CPUPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                                     PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/2);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad2 && max == uklad4)
                             {
                                     new WinnerFrame("Remis pomiedzy " +  PokerFrame.CPUPlayers[0].imie + " " + PokerFrame.CPUPlayers[2].imie);
                                     PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
                                     PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + (PokerFrame.pula/2);
                                     PokerFrame.pula = 0;
                             }
                             else if(max == uklad3 && max == uklad4)
                             {
                                     new WinnerFrame("Remis pomiedzy " +  PokerFrame.CPUPlayers[1].imie + " " + PokerFrame.CPUPlayers[2].imie);
                                     PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/2);
                                     PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + (PokerFrame.pula/2);
                                     PokerFrame.pula = 0;
                             }
                             
                             else if(champion == 0) {
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + PokerFrame.pula;
                                     new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[0].imie);
                                     PokerFrame.pula = 0;
                             }
                             else if(champion == 1) {
                                 PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + PokerFrame.pula;
                                     new WinnerFrame("Runde wygrywa " + PokerFrame.CPUPlayers[0].imie);
                                     PokerFrame.pula = 0;
                             }
                             else if(champion == 2) {                                
                                 PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + PokerFrame.pula;
                                     new WinnerFrame("Runde wygrywa " + PokerFrame.CPUPlayers[1].imie);
                                     PokerFrame.pula = 0;
                             }
                             else if(champion == 3) {
                                 PokerFrame.CPUPlayers[2].money = PokerFrame.CPUPlayers[2].money + PokerFrame.pula;
                                     new WinnerFrame("Runde wygrywa " + PokerFrame.CPUPlayers[2].imie);
                                     PokerFrame.pula = 0;
                             }
                             
             
                             
                             
                     }
                 else if(PlayerFrame.HumAmount == 2)
                 {
                	 int champion = 0;
                	 int uklad1 = 0;
                     int uklad2 = 0;
                     int uklad3 = 0;
                     int uklad4 = 0;
                     
                     uklad1 = Scheme.Uklady(PokerFrame.HumanPlayers[0].Hand);
                     uklad2 = Scheme.Uklady(PokerFrame.HumanPlayers[1].Hand);
                     uklad3 = Scheme.Uklady(PokerFrame.CPUPlayers[0].Hand);
                     uklad4 = Scheme.Uklady(PokerFrame.CPUPlayers[1].Hand);
                     
                         if(account[0] < 0)
                         {
                                 uklad1 = -1;
                         }
                         if(account[1] < 0)
                         {
                                 uklad2 = -1;
                         }
                         if(account[2] < 0)
                         {
                                 uklad3 = -1;
                         }
                         if(account[3] < 0)
                         {
                                 uklad4 = -1;
                         }
         
         //champion = Scheme.compareCards(uklad1, uklad2, uklad3, uklad4);
         int max = uklad1;
         if(max < uklad2)
         {
             max = uklad2;
             champion = 1;
         }
         if(max < uklad3)
         {
             max = uklad3;
             champion = 2;
         }
         if(max < uklad4)
         {
             max = uklad4;
             champion = 3;
         }
         //chujnia ale narazie niech zostanie
         if(max == uklad1 && max == uklad2 && max == uklad3 && max == uklad4)
         {
             new WinnerFrame("Remis pomiedzy wszystkimi graczami!");
             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/4);
             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/4);
             PokerFrame.CPUPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/4);
             PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/4);
             PokerFrame.pula = 0;
         }
         else if(max == uklad1 && max == uklad2 && max == uklad3)
         {
             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.CPUPlayers[0].imie);
             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
             PokerFrame.pula = 0;
         }
         else if(max == uklad1 && max == uklad2 && max == uklad4)
         {
             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.CPUPlayers[1].imie);
             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
             PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/3);
             PokerFrame.pula = 0;
         }
         else if(max == uklad1 && max == uklad3 && max == uklad4)
         {
             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[0].imie + " " + PokerFrame.CPUPlayers[1].imie);
             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
             PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/3);
             PokerFrame.pula = 0;
         }
         else if(max == uklad2 && max == uklad3 && max == uklad4)
         {
             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[2].imie + " " + PokerFrame.CPUPlayers[1].imie);
             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
             PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/3);
             PokerFrame.pula = 0;
         }
         else if(max == uklad1 && max == uklad2)
         {
             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie);
             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
             PokerFrame.pula = 0;
         }
         else if(max == uklad1 && max == uklad3)
         {
             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[0].imie);
             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
             PokerFrame.pula = 0;
         }
         else if(max == uklad1 && max == uklad4)
         {
             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[1].imie);
             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
             PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/2);
             PokerFrame.pula = 0;
         }
         else if(max == uklad2 && max == uklad3)
         {
             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.CPUPlayers[0].imie);
             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
             PokerFrame.pula = 0;
         }
         else if(max == uklad2 && max == uklad4)
         {
             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.CPUPlayers[1].imie);
             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
             PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/2);
             PokerFrame.pula = 0;
         }
         else if(max == uklad3 && max == uklad4)
         {
             new WinnerFrame("Remis pomiedzy " +  PokerFrame.CPUPlayers[0].imie + " " + PokerFrame.CPUPlayers[1].imie);
             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
             PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + (PokerFrame.pula/2);
             PokerFrame.pula = 0;
         }
         else if(champion == 0)
                     {
        	 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[0].imie);
                             PokerFrame.pula = 0;
                     }
                     else if(champion == 1)
                     {
                    	 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[1].imie);
                             PokerFrame.pula = 0;
                     }
                     else if(champion == 2)
                     {
                    	 PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.pula = 0;
                     }
                     else if(champion == 3)
                     {
                    	 PokerFrame.CPUPlayers[1].money = PokerFrame.CPUPlayers[1].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.CPUPlayers[1].imie);
                             PokerFrame.pula = 0;
                     }
                 }
                 else if(PlayerFrame.HumAmount == 3)
                 {
                	 int champion  = 0;
                	 int uklad1 = 0;
                     int uklad2 = 0;
                     int uklad3 = 0;
                     int uklad4 = 0;
                     
                     uklad1 = Scheme.Uklady(PokerFrame.HumanPlayers[0].Hand);
                     uklad2 = Scheme.Uklady(PokerFrame.HumanPlayers[1].Hand);
                     uklad3 = Scheme.Uklady(PokerFrame.HumanPlayers[2].Hand);
                     uklad4 = Scheme.Uklady(PokerFrame.CPUPlayers[0].Hand);
                     
                         if(account[0] < 0)
                         {
                                 uklad1 = -1;
                         }
                         if(account[1] < 0)
                         {
                                 uklad2 = -1;
                         }
                         if(account[2] < 0)
                         {
                                 uklad3 = -1;
                         }
                         if(account[3] < 0)
                         {
                                 uklad4 = -1;
                         }
                     
                     int max = uklad1;
                     if(max < uklad2)
                     {
                             max = uklad2;
                             champion = 1;
                     }
                     if(max < uklad3)
                     {
                             max = uklad3;
                             champion = 2;
                     }
                     if(max < uklad4)
                     {
                             max = uklad4;
                             champion = 3;
                     }
                     //chujnia ale narazie niech zostanie
                     if(max == uklad1 && max == uklad2 && max == uklad3 && max == uklad4)
                     {
                             new WinnerFrame("Remis pomiedzy wszystkimi graczami!");
                             PokerFrame.HumanPlayers[0].money = PlayerFrame.HumanPlayers[0].money + (PokerFrame.pula/4);
                             PokerFrame.HumanPlayers[1].money = PlayerFrame.HumanPlayers[1].money + (PokerFrame.pula/4);
                             PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/4);
                             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/4);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad1 && max == uklad2 && max == uklad3)
                     {
                             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[2].imie);
                             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
                             PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/3);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad1 && max == uklad2 && max == uklad4)
                     {
                             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
                             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad1 && max == uklad3 && max == uklad4)
                     {
                             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[2].imie + " " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                             PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/3);
                             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad2 && max == uklad3 && max == uklad4)
                     {
                             new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[2].imie + " " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
                             PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/3);
                             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/3);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad1 && max == uklad2)
                     {
                             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie);
                             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad1 && max == uklad3)
                     {
                             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[2].imie);
                             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                             PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/2);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad1 && max == uklad4)
                     {
                             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad2 && max == uklad3)
                     {
                             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[2].imie);
                             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
                             PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/2);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad2 && max == uklad4)
                     {
                             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
                             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
                             PokerFrame.pula = 0;
                     }
                     else if(max == uklad3 && max == uklad4)
                     {
                             new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[2].imie + " " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/2);
                             PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + (PokerFrame.pula/2);
                             PokerFrame.pula = 0;
                     }
                     //champion = Scheme.compareCards(uklad1, uklad2, uklad3, uklad4);
                     
                     else if(champion == 0)
                     {
                    	 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[0].imie);
                             PokerFrame.pula = 0;
                     }
                     else if(champion == 1)
                     {
                    	 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[1].imie);
                             PokerFrame.pula = 0;
                     }
                     else if(champion == 2)
                     {
                    	 PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[2].imie);
                             PokerFrame.pula = 0;
                     }
                     else if(champion == 3)
                     {
                    	 PokerFrame.CPUPlayers[0].money = PokerFrame.CPUPlayers[0].money + PokerFrame.pula;
                             new WinnerFrame("Runde wygrywa " + PokerFrame.CPUPlayers[0].imie);
                             PokerFrame.pula = 0;
                     }
                 }
                 else if(PlayerFrame.HumAmount == 4)
                 {
                         
                     int uklad1 = 0;
                     int uklad2 = 0;
                     int uklad3 = 0;
                     int uklad4 = 0;
                     
                     uklad1 = Scheme.Uklady(PokerFrame.HumanPlayers[0].Hand);
                     uklad2 = Scheme.Uklady(PokerFrame.HumanPlayers[1].Hand);
                     uklad3 = Scheme.Uklady(PokerFrame.HumanPlayers[2].Hand);
                     uklad4 = Scheme.Uklady(PokerFrame.HumanPlayers[3].Hand);
                     
                         if(account[0] < 0)
                         {
                                 uklad1 = -1;
                         }
                         if(account[1] < 0)
                         {
                                 uklad2 = -1;
                         }
                         if(account[2] < 0)
                         {
                                 uklad3 = -1;
                         }
                         if(account[3] < 0)
                         {
                                 uklad4 = -1;
                         }
                         

                                 PokerFrame.PlayerNumber = 0;
                         
                         int champion = 0;
                         
                         
                         
                         int remis;
                         int max = uklad1;
                         if(max < uklad2)
                         {
                                 max = uklad2;
                                 champion = 1;
                         }
                         if(max < uklad3)
                         {
                                 max = uklad3;
                                 champion = 2;
                         }
                         if(max < uklad4)
                         {
                                 max = uklad4;
                                 champion = 3;
                         }
                         //chujnia ale narazie niech zostanie
                         if(max == uklad1 && max == uklad2 && max == uklad3 && max == uklad4)
                         {
                                 new WinnerFrame("Remis pomiedzy wszystkimi graczami!");
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/4);
                                 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/4);
                                 PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/4);
                                 PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + (PokerFrame.pula/4);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad1 && max == uklad2 && max == uklad3)
                         {
                                 new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[2].imie);
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/3);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad1 && max == uklad2 && max == uklad4)
                         {
                                 new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[3].imie);
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + (PokerFrame.pula/3);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad1 && max == uklad3 && max == uklad4)
                         {
                                 new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[2].imie + " " + PokerFrame.HumanPlayers[3].imie);
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + (PokerFrame.pula/3);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad2 && max == uklad3 && max == uklad4)
                         {
                                 new WinnerFrame("Remis pomiedzy graczami: " + PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[2].imie + " " + PokerFrame.HumanPlayers[3].imie);
                                 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/3);
                                 PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + (PokerFrame.pula/3);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad1 && max == uklad2)
                         {
                                 new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[1].imie);
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                                 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad1 && max == uklad3)
                         {
                                 new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[2].imie);
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                                 PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/2);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad1 && max == uklad4)
                         {
                                 new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[0].imie + " " + PokerFrame.HumanPlayers[3].imie);
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + (PokerFrame.pula/2);
                                 PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + (PokerFrame.pula/2);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad2 && max == uklad3)
                         {
                                 new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[2].imie);
                                 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
                                 PokerFrame.HumanPlayers[2].money =PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/2);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad2 && max == uklad4)
                         {
                                 new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[1].imie + " " + PokerFrame.HumanPlayers[3].imie);
                                 PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + (PokerFrame.pula/2);
                                 PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + (PokerFrame.pula/2);
                                 PokerFrame.pula = 0;
                         }
                         else if(max == uklad3 && max == uklad4)
                         {
                                 new WinnerFrame("Remis pomiedzy " +  PokerFrame.HumanPlayers[2].imie + " " + PokerFrame.HumanPlayers[3].imie);
                                 PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + (PokerFrame.pula/2);
                                 PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + (PokerFrame.pula/2);
                                 PokerFrame.pula = 0;
                         }
                         
                         //champion = Scheme.compareCards(uklad1, uklad2, uklad3, uklad4);
                         
                         else if(champion == 0)
                                 {
                                 PokerFrame.HumanPlayers[0].money = PokerFrame.HumanPlayers[0].money + PokerFrame.pula;
                                         new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[0].imie);
                                         PokerFrame.pula = 0;
                                 }
                                 else if(champion == 1)
                                 {
                                         PokerFrame.HumanPlayers[1].money = PokerFrame.HumanPlayers[1].money + PokerFrame.pula;
                                         new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[1].imie);
                                         PokerFrame.pula = 0;
                                 }
                                 else if(champion == 2)
                                 {
                                         PokerFrame.HumanPlayers[2].money = PokerFrame.HumanPlayers[2].money + PokerFrame.pula;
                                         new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[2].imie);
                                         PokerFrame.pula = 0;
                                 }
                                 else if(champion == 3)
                                 {
                                         PokerFrame.HumanPlayers[3].money = PokerFrame.HumanPlayers[3].money + PokerFrame.pula;
                                         new WinnerFrame("Runde wygrywa " + PokerFrame.HumanPlayers[3].imie);
                                         PokerFrame.pula = 0;
                                 }
                 }
                 if(PlayerFrame.CPUAmount == 3) {
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[0].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula +PokerFrame.CPUPlayers[0].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.CPUPlayers[1].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.CPUPlayers[2].pobierzWpisowe();

                 }
                 if(PlayerFrame.CPUAmount == 2) {
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[0].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[1].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.CPUPlayers[0].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.CPUPlayers[1].pobierzWpisowe();

                 }
                 if(PlayerFrame.CPUAmount == 1) {
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[0].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[1].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[2].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.CPUPlayers[0].pobierzWpisowe();

                 }
                 
                 if(PlayerFrame.CPUAmount == 0) {
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[0].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[1].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[2].pobierzWpisowe();
                	 PokerFrame.pula = PokerFrame.pula + PokerFrame.HumanPlayers[3].pobierzWpisowe();

                 }
                dispose();
            }
            
            
        }
    
    
    private static void Check() {
    	if(PokerFrame.HumanPlayers[0].money < 5) {
    		raise1.setEnabled(false);
    		call1.setEnabled(false);
    	}
    	if(PokerFrame.HumanPlayers[1].money < 5) {
			raise2.setEnabled(false);
			call2.setEnabled(false);
    	}
    	if(PokerFrame.HumanPlayers[2].money < 5) {
			raise3.setEnabled(false);
			call3.setEnabled(false);
    	}
    	if(PokerFrame.HumanPlayers[3].money < 5) {
			raise4.setEnabled(false);
			call4.setEnabled(false);
	}
    }

}